﻿#region Microsoft Reciprocal License (Ms-RL)
/*
				This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software.

				1. Definitions
				The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law. A "contribution" is the original software, or any additions or changes to the software. A "contributor" is any person that distributes its contribution under this license. "Licensed patents" are a contributor's patent claims that read directly on its contribution.

				2. Grant of Rights
				(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
				(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.

				3. Conditions and Limitations
				(A) Reciprocal Grants- For any file you distribute that contains code from the software (in source code or binary format), you must provide recipients the source code to that file along with a copy of this license, which license will govern that file. You may license other files that are entirely your own work and do not contain code from the software under any terms you choose.
				(B) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
				(C) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically.
				(D) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software.
				(E) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license.
				(F) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.
				*/
#endregion

using System;
using System.Collections.Generic;
using System.Reflection;
using System.Windows.Forms;
using Anheledir.NamesLibrary;
using Anheledir.Tools;

namespace Anheledir.XmlDialogEditor {
  public partial class Form1 : Form {
    private XmlDialog _dialog;
    private FtpClient _remote;
    private bool _changed;
    private string _dialogFilename = string.Empty;
    private XmlDialogView _window = XmlDialogView.Listview;
    private List<XmlDialogEntry> _tempEntries;
    private string formTitle = "XML Dialog-Editor V" + Assembly.GetExecutingAssembly().GetName().Version.ToString();

    public Form1() {
      InitializeComponent();
    }

    private void Form1_Load( object sender, EventArgs e ) {
      _dialog = new XmlDialog();
      RefreshView();
      loadDialogHeader();
      ClearEditPanel();
      this.Text = formTitle;
      _changed = false;

      entryHue.Items.Add( "-1" );
      switch ( Anheledir.XmlDialogEditor.Properties.Settings.Default.lng ) {
        case 2:
          languages.Culture = new System.Globalization.CultureInfo( "de-DE" );
          menuViewLanguageEnglish.Checked = false;
          menuViewLanguageGerman.Checked = true;
          break;
        default:
          languages.Culture = new System.Globalization.CultureInfo( "en-US" );
          menuViewLanguageEnglish.Checked = true;
          menuViewLanguageGerman.Checked = false;
          break;
      }
      RefreshFormLanguage();
    }

    private void button15_Click( object sender, EventArgs e ) {
      switchToTreeview.Enabled = true;
      switchToListview.Enabled = false;
      treeView1.Visible = false;
      listView1.Visible = true;
      MenuViewListview.Checked = true;
      MenuViewTreeview.Checked = false;
      _window = XmlDialogView.Listview;
      RefreshView();
    }

    private void button14_Click( object sender, EventArgs e ) {
      switchToTreeview.Enabled = false;
      switchToListview.Enabled = true;
      treeView1.Visible = true;
      listView1.Visible = false;
      MenuViewListview.Checked = false;
      MenuViewTreeview.Checked = true;
      _window = XmlDialogView.Treeview;
      RefreshView();
    }

    private void closeToolStripMenuItem_Click( object sender, EventArgs e ) {
      Application.Exit();
    }

    private void toolStripMenuItem1_Click( object sender, EventArgs e ) {
      Form about = new AboutBox1();
      about.ShowDialog();
    }

    private void saveasToolStripMenuItem_Click( object sender, EventArgs e ) {
      if ( saveDialogHeader() ) {
        if ( _remote != null ) {
          try {
            remoteBrowser rem = new remoteBrowser( _remote.GetFileList( "*.npc" ), true );
            if ( rem.ShowDialog( this ) == DialogResult.OK ) {
              _dialogFilename = rem.getFile();
              XmlIO.saveRemoteDialog( _dialog, ref _dialogFilename, _remote );
              this.Text = formTitle + " - " + languages.TitleRemote + " " + _dialogFilename;
              _changed = false;
              statusChange( languages.StatusDialogSaved, StatusCode.note );
            }
            rem.Dispose();
          } catch ( FtpClient.FtpException lex ) {
            statusChange( lex.Message, StatusCode.error );
          }
        } else {
          SaveFileDialog dlg = new SaveFileDialog();
          dlg.Filter = languages.SaveOpenDialogFilter;
          dlg.Title = languages.SaveDialogTitle;
          dlg.InitialDirectory = System.Environment.GetFolderPath( Environment.SpecialFolder.MyDocuments );
          dlg.AddExtension = true;
          dlg.DefaultExt = "npc";
          dlg.OverwritePrompt = true;
          if ( dlg.ShowDialog() == DialogResult.OK ) {
            _dialogFilename = dlg.FileName;
            XmlIO.saveXmlDialog( _dialog, _dialogFilename );
            this.Text = formTitle + " - " + _dialogFilename;
            _changed = false;
            statusChange( languages.StatusDialogSaved, StatusCode.note );
          }
        }
      } else {
        if ( dialogName.Text == string.Empty ) {
          statusChange( languages.NameEmpty, StatusCode.error );
        } else {
          statusChange( languages.ErrorSaveHeader, StatusCode.error );
        }
      }
    }

    private void openToolStripMenuItem_Click( object sender, EventArgs e ) {
      if ( _changed ) {
        DialogResult result = MessageBox.Show( languages.SaveChanges, languages.UnsavedChanges, MessageBoxButtons.YesNo, MessageBoxIcon.Question );
        if ( result == System.Windows.Forms.DialogResult.Yes ) {
          MenuFileSave_Click( sender, e );
        }
      }

      if ( _remote != null ) {
        try {
          remoteBrowser rem = new remoteBrowser( _remote.GetFileList( "*.npc" ), false );
          if ( rem.ShowDialog( this ) == DialogResult.OK ) {
            _dialogFilename = rem.getFile();
            XmlDialogEntry.ResetCounter();
            _dialog = XmlIO.loadRemoteDialog( _dialogFilename, _remote );
            _changed = false;
            loadDialogHeader();
            RefreshView();
            statusChange( languages.StatusDialogLoaded, StatusCode.note );
            this.Text = formTitle + " - " + languages.TitleRemote + " " + _dialogFilename;
            _changed = false;
          }
          rem.Dispose();
        } catch ( FtpClient.FtpException lex ) {
          statusChange( lex.Message, StatusCode.error );
          MenuConnectDisconnectFromServer_Click( sender, e );
        }
      } else {
        OpenFileDialog dlg2 = new OpenFileDialog();
        dlg2.Filter = languages.SaveOpenDialogFilter;
        dlg2.Title = languages.OpenDialog;
        dlg2.Multiselect = false;
        dlg2.InitialDirectory = System.Environment.GetFolderPath( Environment.SpecialFolder.MyDocuments );
        if ( dlg2.ShowDialog() == DialogResult.OK ) {
          _dialogFilename = dlg2.FileName;
          XmlDialogEntry.ResetCounter();
          _dialog = XmlIO.loadXmlDialog( _dialogFilename );
          _changed = false;
          loadDialogHeader();
          RefreshView();
          statusChange( languages.StatusDialogLoaded, StatusCode.note );
          this.Text = formTitle + " - " + dlg2.SafeFileName;
          _changed = false;
        }
      }
    }

    private void button11_Click( object sender, EventArgs e ) {
      _changed = true;
      panel_edit.Enabled = true;
      panel_center.Enabled = false;
      panel_header.Enabled = false;
      menuStrip1.Enabled = false;
      int nE = _dialog.AddEntry();
      RefreshEditPanel( _dialog.GetEntry( nE ) );
      RefreshView();
      statusChange( string.Format( languages.NewEntry, nE.ToString() ), StatusCode.note );
    }

    private void button10_Click( object sender, EventArgs e ) {
      using ( XmlDialogEntry de = new XmlDialogEntry( true ) ) {
        de.Id = Convert.ToInt32( entryID.Text );
        de.Depends = entryDependsOn.Text;
        de.Prepause = Convert.ToInt32( entryPrePause.Text );
        de.Pause = Convert.ToInt32( entryPause.Text );
        de.Hue = Convert.ToInt32( entryHue.Text );
        de.LockOn = entryLockOn.Checked;
        de.AllowNpc = entryAllowNPC.Checked;
        de.IgnoreCar = entryIgnoreCar.Checked;
        de.Keywords = entryKeywords.Text;
        de.Text = entryText.Text;
        de.Condition = entryCondition.Text;
        de.Action = entryAction.Text;
        de.Gump = entryGump.Text;

        _dialog.UpdateEntry( Convert.ToInt32( entryUID.Text ), de );
        _changed = true;

        if ( _tempEntries != null ) {
          foreach ( XmlDialogEntry tde in _tempEntries ) {
            _dialog.AddEntry( tde.Id, tde.Depends, tde.Prepause, tde.Pause, tde.Hue, tde.LockOn, tde.AllowNpc, tde.IgnoreCar, tde.Keywords, tde.Text, tde.Condition, tde.Action, tde.Gump );
          }
        }
        _tempEntries = null;

        statusChange( languages.EntrySaved, StatusCode.note );

        panel_edit.Enabled = false;
        panel_center.Enabled = true;
        panel_header.Enabled = true;
        menuStrip1.Enabled = true;
        ClearEditPanel();
        RefreshView();
      }
    }

    private void button8_Click( object sender, EventArgs e ) {
      statusChange( string.Format( languages.EntryDeleted, entryUID.Text ), StatusCode.note );
      _dialog.DeleteEntry( Convert.ToInt32( entryUID.Text ) );
      _changed = true;

      panel_edit.Enabled = false;
      panel_center.Enabled = true;
      panel_header.Enabled = true;
      menuStrip1.Enabled = true;
      ClearEditPanel();
      RefreshView();
    }

    private void button9_Click( object sender, EventArgs e ) {
      ClearEditPanel();
      RefreshEditPanel( _dialog.GetEntry( Convert.ToInt32( entryUID.Text ) ) );
    }

    private void listView1_DoubleClick( object sender, EventArgs e ) {
      if ( listView1.SelectedItems[0].Text != "10" ) {
        panel_edit.Enabled = true;
        panel_center.Enabled = false;
        panel_header.Enabled = false;
        menuStrip1.Enabled = false;
        RefreshEditPanel( _dialog.GetEntry( Convert.ToInt32( listView1.SelectedItems[0].Text ) ) );
      } else {
        statusChange( languages.EditPermitted, StatusCode.warn );
      }
    }

    private void button12_Click( object sender, EventArgs e ) {
      int tmp = 0;
      if ( _window == XmlDialogView.Listview ) {
        foreach ( ListViewItem lvi in listView1.SelectedItems ) {
          if ( lvi.Text != "10" ) {
            _dialog.DeleteEntry( Convert.ToInt32( lvi.Text ) );
            _changed = true;
            tmp++;
          }
        }
      } else if ( _window == XmlDialogView.Treeview ) {
        foreach ( TreeNode tn in treeView1.Nodes ) {
          if ( tn.Checked ) {
            _dialog.DeleteEntry( Convert.ToInt32( tn.Text.Substring( 1, tn.Text.IndexOf( ']' ) - 1 ) ) );
            _changed = true;
            tmp++;
          }
        }
      }
      RefreshView();
      statusChange( string.Format( languages.EntriesDeleted, tmp.ToString() ), StatusCode.note );
    }

    private void button13_Click( object sender, EventArgs e ) {
      int tmp = 0;
      if ( _window == XmlDialogView.Listview ) {
        foreach ( ListViewItem lvi in listView1.SelectedItems ) {
          if ( lvi.Text != "10" ) {
            _dialog.DupeEntry( Convert.ToInt32( lvi.Text ) );
            _changed = true;
            tmp++;
          }
        }
      } else if ( _window == XmlDialogView.Treeview ) {
        foreach ( TreeNode tn in treeView1.Nodes ) {
          if ( tn.Checked ) {
            _dialog.DupeEntry( Convert.ToInt32( tn.Text.Substring( 1, tn.Text.IndexOf( ']' ) - 1 ) ) );
            _changed = true;
            tmp++;
          }
        }
      }
      RefreshView();
      statusChange( string.Format( languages.EntriesDuped, tmp.ToString() ), StatusCode.note );
    }

    private void button16_Click( object sender, EventArgs e ) {
      panel_edit.Enabled = false;
      panel_center.Enabled = true;
      panel_header.Enabled = true;
      menuStrip1.Enabled = true;
      ClearEditPanel();
      RefreshView();
    }

    private void dialogName_TextChanged( object sender, EventArgs e ) {
      _changed = true;
    }

    private void dialogProximityRange_TextChanged( object sender, EventArgs e ) {
      _changed = true;
    }

    private void dialogResetTime_TextChanged( object sender, EventArgs e ) {
      _changed = true;
    }

    private void dialogSpeechPace_TextChanged( object sender, EventArgs e ) {
      _changed = true;
    }

    private void dialogTrigOnCarried_TextChanged( object sender, EventArgs e ) {
      _changed = true;
    }

    private void dialogNoTrigOnCarried_TextChanged( object sender, EventArgs e ) {
      _changed = true;
    }

    private void dialogGhostTrig_CheckedChanged( object sender, EventArgs e ) {
      _changed = true;
    }

    private void Form1_FormClosing( object sender, FormClosingEventArgs e ) {
      DialogResult result = MessageBox.Show( languages.CloseApplication, languages.Exit, MessageBoxButtons.YesNo, MessageBoxIcon.Question );
      if ( result == System.Windows.Forms.DialogResult.Yes ) {
        if ( _changed ) {
          DialogResult result2 = MessageBox.Show( languages.SaveChanges, languages.UnsavedChanges, MessageBoxButtons.YesNo, MessageBoxIcon.Question );
          if ( result2 == System.Windows.Forms.DialogResult.Yes ) {
            MenuFileSave_Click( sender, e );
            e.Cancel = true;
          }
        }
      } else {
        e.Cancel = true;
      }

      if ( ( !e.Cancel ) && ( _remote != null ) ) {
        _remote.Close();
        _remote = null;
      }
      Anheledir.XmlDialogEditor.Properties.Settings.Default.Save();
    }

    private void MenuFileSave_Click( object sender, EventArgs e ) {
      if ( _dialogFilename == string.Empty ) {
        saveasToolStripMenuItem_Click( sender, e );
      } else {
        if ( saveDialogHeader() ) {
          if ( _remote != null ) {
            try {
              XmlIO.saveRemoteDialog( _dialog, ref _dialogFilename, _remote );
            } catch ( FtpClient.FtpException lex ) {
              statusChange( lex.Message, StatusCode.error );
              MenuConnectDisconnectFromServer_Click( sender, e );
            }
          } else {
            XmlIO.saveXmlDialog( _dialog, _dialogFilename );
          }
          _changed = false;
          statusChange( languages.StatusDialogSaved, StatusCode.note );
        } else {
          if ( dialogName.Text == string.Empty ) {
            statusChange( languages.NameEmpty, StatusCode.error );
          } else {
            statusChange( languages.ErrorSaveHeader, StatusCode.error );
          }
        }
      }
    }

    private void statusReset_Tick( object sender, EventArgs e ) {
      statusReset.Enabled = false;
      statusReset.Stop();
      statusLabel.Text = "";
    }

    private void MenuFileNew_Click( object sender, EventArgs e ) {
      if ( _changed ) {
        DialogResult result2 = MessageBox.Show( languages.SaveChanges, languages.UnsavedChanges, MessageBoxButtons.YesNo, MessageBoxIcon.Question );
        if ( result2 == System.Windows.Forms.DialogResult.Yes ) {
          MenuFileSave_Click( sender, e );
        }
      }
      _dialog = new XmlDialog();
      XmlDialogEntry.ResetCounter();
      _changed = false;
      _dialogFilename = string.Empty;
      this.Text = formTitle;
      statusChange( languages.NewDialog, StatusCode.note );
      loadDialogHeader();
      RefreshView();
    }

    private void menuViewLanguageEnglish_Click( object sender, EventArgs e ) {
      languages.Culture = new System.Globalization.CultureInfo( "en-US" );
      menuViewLanguageEnglish.Checked = true;
      menuViewLanguageGerman.Checked = false;
      RefreshFormLanguage();

      Anheledir.XmlDialogEditor.Properties.Settings.Default.lng = 1;
    }

    private void menuViewLanguageGerman_Click( object sender, EventArgs e ) {
      languages.Culture = new System.Globalization.CultureInfo( "de-DE" );
      menuViewLanguageEnglish.Checked = false;
      menuViewLanguageGerman.Checked = true;
      RefreshFormLanguage();

      Anheledir.XmlDialogEditor.Properties.Settings.Default.lng = 2;
    }

    private void treeView1_DoubleClick( object sender, EventArgs e ) {
      if ( treeView1.SelectedNode.Text != "[10] ID 0" ) {
        panel_edit.Enabled = true;
        panel_center.Enabled = false;
        panel_header.Enabled = false;
        menuStrip1.Enabled = false;
        RefreshEditPanel( _dialog.GetEntry( Convert.ToInt32( treeView1.SelectedNode.Text.Substring( 1, treeView1.SelectedNode.Text.IndexOf( ']' ) - 1 ) ) ) );
      } else {
        statusChange( languages.EditPermitted, StatusCode.warn );
      }
    }

    private void menuInfoReportBug_Click( object sender, EventArgs e ) {
      using ( bugreport bg = new bugreport() ) {
        bg.ShowDialog();
      }
    }

    private void wizzardTrogOnCarried_Click( object sender, EventArgs e ) {
      wizardTrigger wiz = new wizardTrigger( dialogTrigOnCarried.Text );
      if ( wiz.ShowDialog( this ) == DialogResult.OK ) {
        dialogTrigOnCarried.Text = wiz.getText();
      } else {
        statusChange( languages.AssistantCancelled, StatusCode.note );
      }
      wiz.Dispose();
    }

    private void WizzardNoTrigOnCarried_Click( object sender, EventArgs e ) {
      wizardTrigger wiz = new wizardTrigger( dialogNoTrigOnCarried.Text );
      if ( wiz.ShowDialog( this ) == DialogResult.OK ) {
        dialogNoTrigOnCarried.Text = wiz.getText();
      } else {
        statusChange( languages.AssistantCancelled, StatusCode.note );
      }
      wiz.Dispose();
    }

    private void WizzardKeywords_Click( object sender, EventArgs e ) {
      wizardKeywords wiz = new wizardKeywords( entryKeywords.Text );
      if ( wiz.ShowDialog( this ) == DialogResult.OK ) {
        entryKeywords.Text = wiz.getText();
      } else {
        statusChange( languages.AssistantCancelled, StatusCode.note );
      }
      wiz.Dispose();
    }

    private void entryHue_SelectedIndexChanged( object sender, EventArgs e ) {
    }

    private void WizzardText_Click( object sender, EventArgs e ) {
      wizardText wiz = new wizardText( entryText.Text );
      if ( wiz.ShowDialog( this ) == DialogResult.OK ) {
        entryText.Text = wiz.getText();
      } else {
        statusChange( languages.AssistantCancelled, StatusCode.note );
      }
      wiz.Dispose();
    }

    private void MenuFileExportTextfile_Click( object sender, EventArgs e ) {
      if ( !_changed ) {
        SaveFileDialog dlg = new SaveFileDialog();
        dlg.Filter = languages.ExportDialogFilter;
        dlg.Title = languages.ExportDialogTitle;
        dlg.InitialDirectory = System.Environment.GetFolderPath( Environment.SpecialFolder.MyDocuments );
        dlg.AddExtension = true;
        dlg.DefaultExt = "txt";
        dlg.OverwritePrompt = true;
        if ( dlg.ShowDialog() == DialogResult.OK ) {
          XmlIO.exportTextfile( _dialog, dlg.FileName );
          statusChange( languages.XMLDialogExported, StatusCode.note );
        }
      } else {
        statusChange( languages.SaveDialogFirst, StatusCode.error );
      }

    }

    private void MenuInfoProjecthomepage_Click( object sender, EventArgs e ) {
      System.Diagnostics.Process.Start( "http://blog.gordon-breuer.de/page/XML-Dialog-Editor.aspx" );
    }

    private void MenuInfoDonations_Click( object sender, EventArgs e ) {
      System.Diagnostics.Process.Start( "https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=mail%40anheledir%2ede&item_name=XML%20Dialog%2dEditor&no_shipping=1&return=http%3a%2f%2fwww%2egordon%2dbreuer%2ede&no_note=1&tax=0&currency_code=EUR&bn=PP%2dDonationsBF&charset=UTF%2d8" );
    }

    private void MenuConnectOptions_Click( object sender, EventArgs e ) {
      if ( _remote == null ) {
        remoteOptions opt = new remoteOptions( Anheledir.XmlDialogEditor.Properties.Settings.Default.RemoteServer, Anheledir.XmlDialogEditor.Properties.Settings.Default.RemotePort, Anheledir.XmlDialogEditor.Properties.Settings.Default.RemoteUser, EncDec.Decrypt(Anheledir.XmlDialogEditor.Properties.Settings.Default.RemotePassword) );
        if ( opt.ShowDialog( this ) == DialogResult.OK ) {
          Anheledir.XmlDialogEditor.Properties.Settings.Default.RemoteServer = opt.getServer();
          Anheledir.XmlDialogEditor.Properties.Settings.Default.RemotePort = opt.getPort();
          Anheledir.XmlDialogEditor.Properties.Settings.Default.RemoteUser = opt.getUser();
          Anheledir.XmlDialogEditor.Properties.Settings.Default.RemotePassword = EncDec.Encrypt( opt.getPsw() );
        }
        opt.Dispose();
      } else {
        MenuConnectConnecttoserver.Enabled = false;
        MenuConnectOptions.Enabled = false;
        MenuConnectDisconnectFromServer.Enabled = true;
      }
    }

    private void MenuConnectConnecttoserver_Click( object sender, EventArgs e ) {
      try {
        if ( _remote == null ) {
          _remote = new FtpClient( Anheledir.XmlDialogEditor.Properties.Settings.Default.RemoteServer, Anheledir.XmlDialogEditor.Properties.Settings.Default.RemoteUser, EncDec.Decrypt( Anheledir.XmlDialogEditor.Properties.Settings.Default.RemotePassword ), Anheledir.XmlDialogEditor.Properties.Settings.Default.RemotePort );
          _remote.Login();
        }
        MenuConnectConnecttoserver.Enabled = false;
        MenuConnectOptions.Enabled = false;
        MenuConnectDisconnectFromServer.Enabled = true;
        statusLabel.Image = Anheledir.XmlDialogEditor.Properties.Resources.connect;
        ftpTimer.Enabled = true;
        ftpTimer.Start();
      } catch ( FtpClient.FtpException ex ) {
        statusChange( ex.Message, StatusCode.error );
        _remote = null;
      }
    }

    private void MenuConnectDisconnectFromServer_Click( object sender, EventArgs e ) {
      _remote.Close();
      _remote = null;

      MenuConnectConnecttoserver.Enabled = true;
      MenuConnectOptions.Enabled = true;
      MenuConnectDisconnectFromServer.Enabled = false;
      statusLabel.Image = Anheledir.XmlDialogEditor.Properties.Resources.disconnect;
    }

    private void ftpTimer_Tick( object sender, EventArgs e ) {
      if ( _remote == null ) {
        ftpTimer.Stop();
        ftpTimer.Enabled = false;
      } else {
        try {
          _remote.Close();
          _remote.Login();
        } catch { }
      }
    }

    private void WizzardGump_Click( object sender, EventArgs e ) {
      wizardGump wiz = new wizardGump( entryGump.Text );
      if ( wiz.ShowDialog( this ) == DialogResult.OK ) {
        entryGump.Text = wiz.getText();
        _tempEntries = wiz.getResponses( Convert.ToInt32( entryID.Text ) );
      } else {
        statusChange( languages.AssistantCancelled, StatusCode.note );
      }
      wiz.Dispose();
    }

    private void listView1_SelectedIndexChanged( object sender, EventArgs e ) {
      if ( listView1.SelectedItems.Count > 0 ) {
        RefreshEditPanel( _dialog.GetEntry( Convert.ToInt32( listView1.SelectedItems[0].Text ) ) );
      } else {
        ClearEditPanel();
      }
    }

    private void treeView1_NodeMouseClick( object sender, TreeNodeMouseClickEventArgs e ) {
      RefreshEditPanel( _dialog.GetEntry( Convert.ToInt32( e.Node.Text.Substring( 1, e.Node.Text.IndexOf( ']' ) - 1 ) ) ) );
    }

    private void WizzardAction_Click( object sender, EventArgs e ) {
      wizardAction wiz = new wizardAction( entryAction.Text );
      if ( wiz.ShowDialog( this ) == DialogResult.OK ) {
        entryAction.Text = wiz.getText();
      } else {
        statusChange( languages.AssistantCancelled, StatusCode.note );
      }
      wiz.Dispose();
    }
  }
}
